﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;

namespace BigPang.Common.GamePlay
{
    public class GameEventArgs : EventArgs
    {
        public GameObject Object { get; set; }
    }

    public class GameObject : DynamicObject, IDisposable
    {
        public virtual int X { get; set; }
        public virtual int Y { get; set; }

        public string Name { get; set; }

        public int Id { get; set; }

        Dictionary<string, object> mMember = new Dictionary<string, object>();

        public GameObject()
        {
            
        }

        public virtual void OnProcessTick()
        {

        }

        public virtual void OnAdd()
        {

        }

        public virtual void OnRemove()
        {

        }

        public virtual void SetPosition(int x, int y)
        {
            X = x;
            Y = y;
        }

        public void Register()
        {
            GameManager.RegisterObject(this);
        }

        public void Delete()
        {
            Dispose();
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            try
            {
                result = mMember[binder.Name];

                return true;
            }
            catch 
            {
                result = null;

                return false;
            }
        }

        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            mMember[binder.Name] = value;

            return true;
        }

        #region IDisposable 成员

        public void Dispose()
        {
            GameManager.UnregisterObject(this);
        }

        #endregion
    }
}
